/**
 * 场景动作列表
 */
export const stageActionList = [
  {
    label: '相机聚焦目标',
    value: 'flyToLayer',
    defaultValue: {},
    execute: (id: string, value: any) => {
      console.log('flyToLayer', id, value);
      if (id) {
        const { cimInstance } = window;
        cimInstance.api.flyToLayer(id);
      }
    },
  },
  {
    label: '模型动画/剖切',
    value: 'updateTransformationClip',
    defaultValue: {
      type: 'gltfClip',
      name: 'clip',
      duration: 2,
      clipCenter: 'model_center',
      unionClippingRegions: true,
      clipPlanePadding: 5,
      // 下面是在编辑器配置的项
      rate: 1,
      times: 1,
      delay: 0,
      easeType: 'easeInOutQuad',
      scaleConfig: {
        // X轴剖切到中间比例 为1，完全剖切比例为2
        X: [0, 0],
        '-X': [0, 0],
        Y: [0, 0],
        '-Y': [0, 0],
        Z: [0, 0],
        '-Z': [0, 0],
      },
    },
    execute: (id: string, value: any) => {
      console.log('updateTransformationClip', id, value);
      if (id) {
        const { cimInstance } = window;
        const { scaleConfig } = value;
        const tempScaleConfig: Record<string, any> = {};
        for (const key in scaleConfig) {
          if (!Array.isArray(scaleConfig[key])) {
            continue;
          }
          // 换算成 CIMPU 需要的值
          tempScaleConfig[key] = scaleConfig[key].map((o: number) => (o / 100) * 2);
        }
        cimInstance.api.updateTransformation({
          ...value,
          layerName: id,
          scaleConfig: tempScaleConfig,
        });
      }
    },
  },
  {
    label: '模型动画/爆炸',
    value: 'updateTransformationExplode',
    defaultValue: {
      type: 'gltfExplosion',
      name: 'explode',
      layerName: 'box',
      explodeDirection: 'XYZ',
      duration: 2,
      scaleConfig: {
        // 边界为正负 10
        X: [0, 10],
        Y: [0, 10],
        Z: [0, 10],
      },
      // 下面是在编辑器配置的项
      rate: 1,
      times: 1,
      delay: 0,
      easeType: 'easeInOutQuad',
      explodeScale: [0, 0, 0],
    },
    execute: (id: string, value: any) => {
      console.log('updateTransformationExplode', id, value);
      if (id) {
        const { cimInstance } = window;
        const config = {
          ...value,
          layerName: id,
        };
        cimInstance.api.updateTransformation(config);
      }
    },
  },
];

/**
 * 场景动作字典
 */
export const stageActionMap = stageActionList.reduce((prev, current) => {
  prev[current.value] = current.execute;
  return prev;
}, {} as Record<string, any>);
